package com.ruoyi.sms.strategy;

import com.alibaba.fastjson.JSON;
import com.ruoyi.sms.entity.SendReq;
import com.ruoyi.sms.entity.SmsResponse;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.HashMap;
import java.util.Map;


public abstract class SendStrategyContent implements ISendStrategy {

    /**
     * 发送策略预加载
     */
    public static Map<Integer, ISendStrategy> sendStrategyMap = new HashMap<>(20);

    @PostConstruct
    public void init() {
        sendStrategyMap.put(channelInit(), this);
        System.out.println("map:" + JSON.toJSONString(sendStrategyMap));
    }

    @Override
    public SmsResponse toSendCore(SendReq sendReq) {
        // 发送方式列表只有一个手机号，单独发送，否则批量发送
        if (sendReq.getPhoneNumberList().size() == 1){
            return toSend(sendReq);
        } else if (sendReq.getPhoneNumberList().size() > 1){
            return toSendBatch(sendReq);
        }
        return SmsResponse.error("请输入发送人手机号列表！");
    }

    @Override
    public SmsResponse getSmsInfo(SendReq sendReq) {
        return getInfo(sendReq);
    }

    // 短信发送
    public abstract SmsResponse toSend(SendReq sendReq);

    // 批量发送
    public abstract SmsResponse toSendBatch(SendReq sendReq);

    // 查询短信详情
    public abstract SmsResponse getInfo(SendReq sendReq);

    // 获取发送通道
    public abstract Integer channelInit();
}
